<html>

<head>
</head>
<?php
	if($_POST){
		$idPost 	  = $_POST["txtIdPost"];
		$idComentario = $_POST["txtIdComentario"];
		$conteudo 	  = $_POST["txtComentario"];
			
		$doc = new DomDocument();
		$doc->load('../blog.xml');
		
		$comentarios = $doc->getElementsByTagName('comentario');
		
		foreach($comentarios as $comentario){
			$idPostComent = $comentario->getAttribute('idPostComentario');
			$idComent     = $comentario->getAttribute('idComentario');
			
			if($idPost == $idPostComent && $idComentario == $idComent){
				$comentario->getElementsByTagName('conteudo')->item(0)->nodeValue = $conteudo;
				$doc->formatOutput = true;
				
				if($doc->save('../blog.xml')){
					echo "<script>alert('Operação realizada com sucesso!'); window.close();</script>";
				}
			}
		}
		
	}

?>
<body>
<h1>Alterar comentario</h1>
<br />
<form action="alterarComentarioGo.php" method="post">
Comentario:
<br />
<?php

	if(isset($_GET["idPost"]) && isset($_GET["idComentario"])){
	$idPost = $_GET["idPost"];
	$idComentario = $_GET["idComentario"];
	
	$doc = new DomDocument();
	$doc->load('../blog.xml');
	
	$comentarios = $doc->getElementsByTagName('comentario');
	
	foreach($comentarios as $comentario);
		$idPostComentario = $comentario->getAttribute('idPostComentario');
		$idComent         = $comentario->getAttribute('idComentario');
		$coment           = $comentario->getElementsByTagName('conteudo')->item(0)->nodeValue;
		if($idPostComentario == $idPost && $idComentario == $idComent){
			echo "<textarea cols=\"85\" rows=\"25\" name=\"txtComentario\">{$coment}</textarea><br />";
		}
	}
	
?>
<input type="hidden" name="txtIdPost" id="txtIdPost" value= "<?php echo $idPost; ?>" />
<input type="hidden" name="txtIdComentario" id="txtIdComentario" value= "<?php echo $idComentario; ?>" />
<input type="submit" name="btnEnviar" id="btnEviar" value ="Alterar" />

</form>
</body>
</html>